/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp1;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author tulio
 */
abstract public class Relatorio {

    private String nome;

    private Date data;

    private String titulo;

    protected Document doc;

    public Relatorio(){
        this.data = new Date();
    }

    public void criar() throws DocumentException, FileNotFoundException {
        this.doc = new Document();
        PdfWriter.getInstance(this.doc, new FileOutputStream(this.nome + ".pdf"));
        this.doc.open();
        this.escrever();
        this.doc.close();
        this.exec();
    }

    abstract public void escrever() throws DocumentException;

    public void exec(){
        File pdf = new File(this.nome + ".pdf");
        try {
            Desktop.getDesktop().open(pdf);
        } catch(Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(null, "Erro no Desktop: " + ex);
        }
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public String getNome() {
        return nome;
    }
    
    public void setNome(String nome) {
        this.nome = nome + this.getData().toString();
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

}
